package com.ruoyi.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.AuctionSession;
import com.ruoyi.demo.service.IAuctionSessionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 拍卖专场Controller
 *
 * @author metaee
 * @date 2025-03-06
 */
@Api(tags = "拍卖专场管理")
@RestController
@RequestMapping("/demo/session")
public class AuctionSessionController extends BaseController
{
    @Autowired
    private IAuctionSessionService auctionSessionService;

    /**
     * 查询拍卖专场列表
     */
    @ApiOperation("查询拍卖专场列表")
    @PreAuthorize("@ss.hasPermi('demo:session:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuctionSession auctionSession)
    {
        startPage();
        List<AuctionSession> list = auctionSessionService.selectAuctionSessionList(auctionSession);
        return getDataTable(list);
    }

    /**
     * 导出拍卖专场列表
     */
    @ApiOperation("导出拍卖专场列表")
    @PreAuthorize("@ss.hasPermi('demo:session:export')")
    @Log(title = "拍卖专场", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuctionSession auctionSession)
    {
        List<AuctionSession> list = auctionSessionService.selectAuctionSessionList(auctionSession);
        ExcelUtil<AuctionSession> util = new ExcelUtil<AuctionSession>(AuctionSession.class);
        util.exportExcel(response, list, "拍卖专场数据");
    }

    /**
     * 获取拍卖专场详细信息
     */
    @ApiOperation("获取拍卖专场详细信息")
    @PreAuthorize("@ss.hasPermi('demo:session:query')")
    @GetMapping(value = "/{sessionId}")
    public AjaxResult getInfo(@ApiParam(value = "拍卖专场ID", required = true) @PathVariable("sessionId") Long sessionId)
    {
        return success(auctionSessionService.selectAuctionSessionBySessionId(sessionId));
    }

    /**
     * 新增拍卖专场
     */
    @ApiOperation("新增拍卖专场")
    @PreAuthorize("@ss.hasPermi('demo:session:add')")
    @Log(title = "拍卖专场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuctionSession auctionSession)
    {
        return toAjax(auctionSessionService.insertAuctionSession(auctionSession));
    }

    /**
     * 修改拍卖专场
     */
    @ApiOperation("修改拍卖专场")
    @PreAuthorize("@ss.hasPermi('demo:session:edit')")
    @Log(title = "拍卖专场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuctionSession auctionSession)
    {
        return toAjax(auctionSessionService.updateAuctionSession(auctionSession));
    }

    /**
     * 删除拍卖专场
     */
    @ApiOperation("删除拍卖专场")
    @PreAuthorize("@ss.hasPermi('demo:session:remove')")
    @Log(title = "拍卖专场", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sessionIds}")
    public AjaxResult remove(@ApiParam(value = "拍卖专场ID数组", required = true) @PathVariable Long[] sessionIds)
    {
        return toAjax(auctionSessionService.deleteAuctionSessionBySessionIds(sessionIds));
    }
}
